package com.baizhi.service.impl;

import com.baizhi.entity.PmsBrand;
import com.baizhi.dao.PmsBrandMapper;
import com.baizhi.log.LogAnnotation;
import com.baizhi.service.IPmsBrandService;
import com.baizhi.vo.PmsBrandVo;
import com.baizhi.vo.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * InnoDB free: 13312 kB 服务实现类
 * </p>
 *
 * @author lby
 * @since 2020-12-24
 */
@Service
public class PmsBrandServiceImpl extends ServiceImpl<PmsBrandMapper, PmsBrand> implements IPmsBrandService {
    @Override
    public R selectBrandBySize(Integer page, Integer limit) {
        Page<PmsBrand> brandPage = page(new Page<>(page, limit));

        List<PmsBrand> brands = brandPage.getRecords();

        List<PmsBrandVo> list = brands.stream()
                .map(pmsBrand -> {
                    PmsBrandVo brandVo = new PmsBrandVo();
                    BeanUtils.copyProperties(pmsBrand,brandVo);
                    return brandVo;
                })
                .collect(Collectors.toList());

        return R.ok().put("count",brandPage.getTotal()).put("data",list);
    }
}
